package com.dc.dao;

import com.dc.dao.vo.CalibrationShipCutReturnVO;
import com.dc.dao.vo.stat.CalibrationShipCutStatVO;
import com.dc.entity.CalibrationShipCutEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface CalibrationShipCutDao extends JpaRepository<CalibrationShipCutEntity, Long>, JpaSpecificationExecutor<CalibrationShipCutEntity> {

    @Query(nativeQuery = true,
            value = "SELECT " +
                    " tcsc.id AS id," +
                    " tcsc.ship_id as shipId," +
                    " ts.name as shipName," +
                    " tcsc.cut_length as cutLength," +
                    " tcsc.cut_area as cutArea," +
                    " tcsc.type as type," +
                    " tcsc.length as length," +
                    " tcsc.width as width," +
                    " tcsc.thickness as thickness," +
                    " tcsc.num as num," +
                    " tcsc.area as area," +
                    " tcsc.weight as weight," +
                    " tcsc.device as device," +
                    " tcsc.device_no as deviceNo," +
                    " tcsc.start_power as startPower," +
                    " tcsc.end_power as endPower," +
                    " tcsc.power as power," +
                    " tcsc.power_by_unit as powerByUnit," +
                    " tcsc.start_o2 as startO2," +
                    " tcsc.end_o2 as endO2," +
                    " tcsc.o2 as o2," +
                    " tcsc.o2_by_unit as o2ByUnit," +
                    " tcsc.start_air as startAir," +
                    " tcsc.end_air as endAir," +
                    " tcsc.air as air," +
                    " tcsc.air_by_unit as airByUnit " +
                    " FROM " +
                    " t_calibration_ship_cut tcsc " +
                    " JOIN t_ship ts ON tcsc.ship_id = ts.id")
    public List<CalibrationShipCutReturnVO> findAllCuts();

    @Query(nativeQuery = true,
            value = "SELECT " +
                    " tcsc.id AS id," +
                    " tcsc.ship_id as shipId," +
                    " ts.name as shipName," +
                    " tcsc.cut_length as cutLength," +
                    " tcsc.cut_area as cutArea," +
                    " tcsc.type as type," +
                    " tcsc.length as length," +
                    " tcsc.width as width," +
                    " tcsc.thickness as thickness," +
                    " tcsc.num as num," +
                    " tcsc.area as area," +
                    " tcsc.weight as weight," +
                    " tcsc.device as device," +
                    " tcsc.device_no as deviceNo," +
                    " tcsc.start_power as startPower," +
                    " tcsc.end_power as endPower," +
                    " tcsc.power as power," +
                    " tcsc.power_by_unit as powerByUnit," +
                    " tcsc.start_o2 as startO2," +
                    " tcsc.end_o2 as endO2," +
                    " tcsc.o2 as o2," +
                    " tcsc.o2_by_unit as o2ByUnit," +
                    " tcsc.start_air as startAir," +
                    " tcsc.end_air as endAir," +
                    " tcsc.air as air," +
                    " tcsc.air_by_unit as airByUnit " +
                    " FROM " +
                    " t_calibration_ship_cut tcsc " +
                    " JOIN t_ship ts ON tcsc.ship_id = ts.id",
            countQuery = "SELECT count(1) from t_calibration_ship_cut tcsc JOIN t_ship ts ON tcsc.ship_id = ts.id")
    public Page<CalibrationShipCutReturnVO> findAllByPage(Pageable pageable);



    // 暂时没用
    @Query(nativeQuery = true, value = "select power_by_unit as powerUnit," +
                                    " o2_by_unit as o2Unit," +
                                    " air_by_unit as airUnit from t_calibration_ship_cut")
    public List<CalibrationShipCutStatVO> findAllForStat();

}
